package com.xqy.wexmini.controller;

import com.xqy.wexmini.common.ResponseResult;
import com.xqy.wexmini.domain.Content;
import com.xqy.wexmini.form.ShuiguoForm;
import com.xqy.wexmini.utils.Newsutils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@Api(tags = "新闻")
@RestController
@RequestMapping("/news")
public class NewsController {
    @ApiOperation("默认展示的页面,根据页码返回十条数据")
    @PostMapping("/html")
    public ResponseResult getAddress(@RequestBody Integer page) throws IOException {
        List<Content> list = Newsutils.parseJD("水果", page);
        return new ResponseResult(200,list);
    }

    @ApiOperation("根据搜索内容返回十条数据")
    @PostMapping("/html1")
    public ResponseResult getAddress1(@RequestBody ShuiguoForm shuiguoForm) throws IOException {
        List<Content> list = Newsutils.parseJD(shuiguoForm.getType(),shuiguoForm.getPage());
        return new ResponseResult(200,list);
    }
    @ApiOperation("根据url返回")
    @PostMapping("/html2")
    public ResponseResult getAddress2(@RequestBody String url) throws IOException {
        String list = Newsutils.parseJD1(url);
        return new ResponseResult(200,list);
    }
}
